package cn.com.shaom.learning.sb.data.mybatis.page.service;

import cn.com.shaom.learning.sb.data.mybatis.page.dao.IUserMapper;
import cn.com.shaom.learning.sb.data.mybatis.page.entity.User;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * ClassName: UserServiceImpl
 * Description:
 * Date: 2018/1/8 14:30 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
@Transactional(rollbackFor = Exception.class)
@Service
public class UserServiceImpl implements IUserService {

    @Resource
    private IUserMapper userMapper;

    @Override
    public Page<User> findUserByName(String name, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<User> userByName = userMapper.findUserByName(name);
        return (Page<User>) userByName;
    }

    @Override
    public PageInfo<User> getALL(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<User> users = userMapper.getALL();
        return new PageInfo<>(users);
    }
}
